{include file="public/header" /}</head>
<body>
<div class="x-body layui-anim">
    <form class="layui-form" id="form">
        {include file="public/arguments" /}
        <input type="hidden" name="id" value="{$Request.param.id}">
        <input type="hidden" name="pid" value="{$Request.param.pid|default=0}">
        {if $p_title }
        <div class="layui-form-item">
            <label class="layui-form-label">上级菜单</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" value="{$p_title}" disabled="disabled"/>
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>名称</label>
            <div class="layui-input-inline">
                <input type="text" name="title" placeholder="请输入菜单名称" class="layui-input" value="{$info?$info.title:''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>节点</label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" autocomplete="off" placeholder="例如：menu/index " class="layui-input"
                       value="{$info?$info.name:''}">
            </div>
            <div class="layui-form-mid layui-word-aux">请使用驼峰命名</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>排序</label>
            <div class="layui-input-inline">
                <input type="number" name="sort" autocomplete="off" placeholder="请输入排序" class="layui-input"
                       value="{$info?$info.sort:'0'}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>图标</label>
            <div class="layui-input-inline">
                <input type="text" name="css" autocomplete="off" class="layui-input" value="{$info?$info.css:''}">
            </div>
        </div>
        {if !isset($info)}
        <div class="layui-form-item">
            <label class="layui-form-label">自动构建Controller</label>
            <div class="layui-input-block">
                <input type="checkbox" name="autoController" lay-skin="switch" lay-filter="controller" lay-text="是|否" value="1">
            </div>
            <div class="layui-form-mid layui-word-aux">开启后，将自动生成类文件</div>
        </div>
        <div class="controller" style="display:none;">
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">* </span>控制器名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="className" placeholder="请输入控制器名称" autocomplete="off" class="layui-input auto_name" value="">
                </div>
                <div class="layui-form-mid layui-word-aux">控制器的名称，列如Test</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                <div class="layui-input-inline">
                    <input type="text" name="classNamespace" placeholder="请输入命名空间" autocomplete="off" class="layui-input" value="app\admin\controller\">
                </div>
                <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">自动构建Model</label>
            <div class="layui-input-block">
                <input type="checkbox" name="autoModel" lay-skin="switch" lay-filter="model" lay-text="是|否" value="1">
            </div>
            <div class="layui-form-mid layui-word-aux">开启后，将自动生成模型类</div>
        </div>
        <div class="model" style="display:none;">
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">* </span>模型名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="modelName" placeholder="请输入模型名称" autocomplete="off" class="layui-input auto_name" value="">
                </div>
                <div class="layui-form-mid layui-word-aux">模型的名称，列如Test</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                <div class="layui-input-inline">
                    <input type="text" name="modelNamespace" placeholder="请输入命名空间" autocomplete="off" class="layui-input" value="app\common\model\">
                </div>
                <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">* </span>表名</label>
                <div class="layui-input-inline">
                    <input type="text" name="dbName" placeholder="请输入表名" autocomplete="off" class="layui-input db_name" value="">
                </div>
                <div class="layui-form-mid layui-word-aux">Model类对应的数据库表名</div>
            </div>
        </div>
        {/if}

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                确认修改
            </button>
        </div>
    </form>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            $.ajax({
                type: 'POST',
                url: '{:url("menu/save1")}',
                data: $("#form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        layer.alert(data.msg, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
            return false;
        });

        $("#name").blur(function () {
            var value = $(this).val();
            var split = value.split('/');
            if(split[0]){
                $(".auto_name").val(cap(split[0]));
                $(".db_name").val(split[0]);
            }else{
                $(".auto_name").val('');
                $(".db_name").val('');
            }
        });

        function cap(str) {
            return str.replace(/([a-z])/, function (match, value) {
                return value.toUpperCase();
            })
        }

        form.on('switch(controller)', function(data){
            if(data.elem.checked){
                $(".controller").show();
            }else{
                $(".controller").hide();
            }
        });

        form.on('switch(model)', function(data){
            if(data.elem.checked){
                $(".model").show();
            }else{
                $(".model").hide();
            }
        });


    });
</script>
</body>

</html>